using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace _RobotInspection.DTO
{
    /// <summary>
    /// 创建点检计划请求DTO
    /// </summary>
    public class CreateInspectionPlanDto
    {
        /// <summary>
        /// 计划名称
        /// </summary>
        [Required(ErrorMessage = "计划名称不能为空")]
        [StringLength(100, ErrorMessage = "计划名称长度不能超过100个字符")]
        public string PlanName { get; set; }

        /// <summary>
        /// 机组
        /// </summary>
        [Required(ErrorMessage = "机组不能为空")]
        public string Unit { get; set; }
        /// <summary>
        /// 计划类型：1-日点检，2-周点检，3-月点检，4-一次性点检
        /// </summary>
        [Required(ErrorMessage = "计划类型不能为空")]
        [Range(1, 4, ErrorMessage = "计划类型必须在1-4之间")]
        public byte PlanType { get; set; }
        /// <summary>
        /// 是否立即执行 1是，0否
        /// </summary>
        public int IsNow { get; set; }
        /// <summary>
        /// 是否节假日执行：1-是，0-否
        /// </summary>
        [Required(ErrorMessage = "不能为空")]
        public int IsHoliday { get; set; }
        /// <summary>
        /// 频率值（如：每天1次）
        /// </summary>
        public int? FrequencyValue { get; set; }

        /// <summary>
        /// 计划开始日期
        /// </summary>
        public DateTime? StartDate { get; set; }

        /// <summary>
        /// 计划结束日期
        /// </summary>
        public DateTime? EndDate { get; set; }

        /// <summary>
        /// 创建人ID
        /// </summary>
        public long? CreatedBy { get; set; }

        /// <summary>
        /// 指派的用户ID列表（用于点检任务分配）
        /// </summary>
        public List<long> AssignedUserIds { get; set; } = new List<long>();

        /// <summary>
        /// 选中的设备点检项列表
        /// </summary>
        [Required(ErrorMessage = "必须选择至少一个设备点检项")]
        public List<InspectionPlanItemDto> PlanItems { get; set; } = new List<InspectionPlanItemDto>();
    }

    /// <summary>
    /// 点检计划项DTO
    /// </summary>
    public class InspectionPlanItemDto
    {
        /// <summary>
        /// 设备ID
        /// </summary>
        [Required(ErrorMessage = "设备ID不能为空")]
        public long EquipmentId { get; set; }

        /// <summary>
        /// 点检项ID列表
        /// </summary>
        [Required(ErrorMessage = "点检项ID不能为空")]
        public List<long> ItemIds { get; set; } = new List<long>();
    }

    /// <summary>
    /// 点检计划响应DTO
    /// </summary>
    public class InspectionPlanResponseDto
    {
        /// <summary>
        /// 计划ID
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 计划名称
        /// </summary>
        public string PlanName { get; set; }

        /// <summary>
        /// 计划类型：1-日点检，2-周点检，3-月点检，4-一次性点检
        /// </summary>
        public byte PlanType { get; set; }

        /// <summary>
        /// 计划类型名称
        /// </summary>
        public string PlanTypeName { get; set; }

        /// <summary>
        /// 频率值
        /// </summary>
        public int? FrequencyValue { get; set; }

        /// <summary>
        /// 计划开始日期
        /// </summary>
        public DateTime? StartDate { get; set; }

        /// <summary>
        /// 计划结束日期
        /// </summary>
        public DateTime? EndDate { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public byte? IsActive { get; set; }

        /// <summary>
        /// 创建人ID
        /// </summary>
        public long? CreatedBy { get; set; }

        /// <summary>
        /// 创建人姓名
        /// </summary>
        public string CreatedByName { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreatedAt { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime? UpdatedAt { get; set; }

        /// <summary>
        /// 计划包含的设备点检项
        /// </summary>
        public List<PlanItemDetailDto> PlanItems { get; set; } = new List<PlanItemDetailDto>();
    }

    /// <summary>
    /// 计划项详情DTO
    /// </summary>
    public class PlanItemDetailDto
    {
        /// <summary>
        /// 设备ID
        /// </summary>
        public long EquipmentId { get; set; }

        /// <summary>
        /// 设备名称
        /// </summary>
        public string EquipmentName { get; set; }

        /// <summary>
        /// 设备编码
        /// </summary>
        public string EquipmentCode { get; set; }

        /// <summary>
        /// 点检项列表
        /// </summary>
        public List<InspectionItemDetailDto> Items { get; set; } = new List<InspectionItemDetailDto>();
    }

    /// <summary>
    /// 点检项详情DTO
    /// </summary>
    public class InspectionItemDetailDto
    {
        /// <summary>
        /// 点检项ID
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 点检项名称
        /// </summary>
        public string ItemName { get; set; }

        /// <summary>
        /// 点检项描述
        /// </summary>
        public string ItemDescription { get; set; }

        /// <summary>
        /// 标准值
        /// </summary>
        public string StandardValue { get; set; }

        /// <summary>
        /// 单位
        /// </summary>
        public string Unit { get; set; }

        /// <summary>
        /// 排序序号
        /// </summary>
        public int? SortOrder { get; set; }
    }

    /// <summary>
    /// 设备及其点检项DTO（用于选择界面）
    /// </summary>
    public class EquipmentWithItemsDto
    {
        /// <summary>
        /// 设备ID
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 设备名称
        /// </summary>
        public string EquipmentName { get; set; }

        /// <summary>
        /// 设备编码
        /// </summary>
        public string EquipmentCode { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>
        public string CompanyName { get; set; }

        /// <summary>
        /// 机组
        /// </summary>
        public string Crew { get; set; }

        /// <summary>
        /// 该设备的所有点检项
        /// </summary>
        public List<InspectionItemDetailDto> InspectionItems { get; set; } = new List<InspectionItemDetailDto>();
    }

    /// <summary>
    /// 点检计划查询DTO
    /// </summary>
    public class InspectionPlanQueryDto
    {
        /// <summary>
        /// 计划名称（模糊查询）
        /// </summary>
        public string PlanName { get; set; }

        /// <summary>
        /// 计划类型
        /// </summary>
        public byte? PlanType { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public byte? IsActive { get; set; }

        /// <summary>
        /// 创建人ID
        /// </summary>
        public long? CreatedBy { get; set; }

        /// <summary>
        /// 页码
        /// </summary>
        public int PageIndex { get; set; } = 1;

        /// <summary>
        /// 页大小
        /// </summary>
        public int PageSize { get; set; } = 20;
    }

    /// <summary>
    /// 按机组查询点检计划DTO
    /// </summary>
    public class InspectionPlanByUnitDto
    {
        /// <summary>
        /// 计划ID
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 计划名称
        /// </summary>
        public string PlanName { get; set; }

        /// <summary>
        /// 机组
        /// </summary>
        public string Unit { get; set; }

        /// <summary>
        /// 计划类型
        /// </summary>
        public byte PlanType { get; set; }

        /// <summary>
        /// 计划类型名称
        /// </summary>
        public string PlanTypeName { get; set; }

        /// <summary>
        /// 频率值
        /// </summary>
        public int? FrequencyValue { get; set; }

        /// <summary>
        /// 开始日期
        /// </summary>
        public DateTime? StartDate { get; set; }

        /// <summary>
        /// 结束日期
        /// </summary>
        public DateTime? EndDate { get; set; }

        /// <summary>
        /// 是否跳过节假日：1-跳过，0-不跳过
        /// </summary>
        public int IsHoliday { get; set; }

        /// <summary>
        /// 是否跳过节假日描述
        /// </summary>
        public string IsHolidayName { get; set; }

        /// <summary>
        /// 点检项数量
        /// </summary>
        public int ItemCount { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public byte IsActive { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreatedAt { get; set; }
    }

    /// <summary>
    /// 分页查询点检计划请求DTO
    /// </summary>
    public class InspectionPlanPagedQueryDto
    {
        /// <summary>
        /// 机组名称（可选）
        /// </summary>
        public string? Unit { get; set; }

        /// <summary>
        /// 设备ID（可选）
        /// </summary>
        public long? EquipmentId { get; set; }

        /// <summary>
        /// 点检周期类型（可选）：1-日点检，2-周点检，3-月点检，4-一次性点检
        /// </summary>
        public byte? PlanType { get; set; }

        /// <summary>
        /// 计划名称（模糊查询，可选）
        /// </summary>
        public string? PlanName { get; set; }

        /// <summary>
        /// 是否启用（可选）：1-启用，0-禁用
        /// </summary>
        public byte? IsActive { get; set; }

        /// <summary>
        /// 页码，从1开始
        /// </summary>
        public int PageIndex { get; set; } = 1;

        /// <summary>
        /// 页大小，默认20
        /// </summary>
        public int PageSize { get; set; } = 20;
    }

    /// <summary>
    /// 分页查询点检计划响应DTO
    /// </summary>
    public class InspectionPlanPagedResultDto
    {
        /// <summary>
        /// 点检计划列表
        /// </summary>
        public List<InspectionPlanByUnitDto> Items { get; set; } = new List<InspectionPlanByUnitDto>();

        /// <summary>
        /// 总记录数
        /// </summary>
        public int TotalCount { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages { get; set; }

        /// <summary>
        /// 当前页码
        /// </summary>
        public int CurrentPage { get; set; }

        /// <summary>
        /// 页大小
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 是否有上一页
        /// </summary>
        public bool HasPreviousPage { get; set; }

        /// <summary>
        /// 是否有下一页
        /// </summary>
        public bool HasNextPage { get; set; }
    }
}